/**   
 * @Title: AgainstTeamListLocalFilter.java 
 * @Package com.esun.rabbit2.viewer.mainact.lotteryhallact.sportteryfootballapg 
 * @Description: (对阵列表本地筛选) 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-9-5 上午11:42:12  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact.lotteryhallact.sportteryfootballapg;

import java.util.ArrayList;
import java.util.Hashtable;

import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.sportteryfootball.SportteryFootballAgainstInfo;

/**
 * @ClassName: AgainstTeamListLocalFilter
 * @Description: (对阵列表本地筛选)
 * @author: City Jiangsy@500wan.com
 * @date: 2011-9-5 上午11:42:12
 * 
 */
public class AgainstTeamListLocalFilter {
	private ArrayList<Hashtable<String, Object>> list = new ArrayList<Hashtable<String, Object>>();
	// private ArrayList<Hashtable<String, Object>> listResult = new ArrayList<Hashtable<String, Object>>();
	private int rangqiuType;
	private int peilvType;
	private ArrayList<String> leagueNameList;

	public AgainstTeamListLocalFilter(ArrayList<Hashtable<String, Object>> list) {
		this.list = list;
	}

	public ArrayList<Hashtable<String, Object>> getResult(int rangqiuType, int peilvType, ArrayList<String> leagueNameList, boolean isAll) {
		// this.isRecommend = isRecommend;
		this.rangqiuType = rangqiuType;
		this.peilvType = peilvType;
		this.leagueNameList = leagueNameList;
		// listResult.clear();
		for (int i = 0; i < list.size(); i++) {
			if ((Boolean) list.get(i).get(Key.KEY_IS_TITLE)) {
				// listResult.add(list.get(i));
				list.get(i).put(Key.KEY_IS_SHOW, true);
			} else if ((isRightLeague((SportteryFootballAgainstInfo) list.get(i).get(Key.KEY_INFO)) || isAll) && isRightPeilv((SportteryFootballAgainstInfo) list.get(i).get(Key.KEY_INFO))
					&& isRightRangqiu((SportteryFootballAgainstInfo) list.get(i).get(Key.KEY_INFO))) {
				// listResult.add(list.get(i));
				list.get(i).put(Key.KEY_IS_SHOW, true);
			} else {
				list.get(i).put(Key.KEY_IS_SHOW, false);
				list.get(i).put(Key.KEY_IS_ACTIVE, false);
				list.get(i).put(Key.KEY_W, false);
				list.get(i).put(Key.KEY_D, false);
				list.get(i).put(Key.KEY_L, false);
				list.get(i).put(Key.KEY_IS_DAN, false);
			}
		}
		return list;
	}

	// 0:全部,1:让球,2:非让球
	private boolean isRightRangqiu(SportteryFootballAgainstInfo sportteryFootballAgainstInfo) {
		boolean b = false;
		if (rangqiuType == 0) {
			b = true;
		} else if (rangqiuType == 1) {
			if (sportteryFootballAgainstInfo.getRangqiu().equals(Config.NUM0)) {
				b = false;
			} else {
				b = true;
			}
		} else if (rangqiuType == 2) {
			if (sportteryFootballAgainstInfo.getRangqiu().equals(Config.NUM0)) {
				b = true;
			} else {
				b = false;
			}
		} else {
			b = false;
		}
		return b;
	}

	// 0:全部,1:高命中区间,2:实力赔率区间,3:高额回报区间
	private boolean isRightPeilv(SportteryFootballAgainstInfo sportteryFootballAgainstInfo) {
		boolean b = false;

		double w = Double.parseDouble(sportteryFootballAgainstInfo.getWin());
		double d = Double.parseDouble(sportteryFootballAgainstInfo.getDraw());
		double l = Double.parseDouble(sportteryFootballAgainstInfo.getLost());

		if (peilvType == 0) {
			b = true;
		} else if (peilvType == 1) {
			if (w < 1.5) {
				b = true;
			} else if (d < 1.5) {
				b = true;
			} else if (l < 1.5) {
				b = true;
			} else {
				b = false;
			}
		} else if (peilvType == 2) {
			if (w >= 1.5 && d < 2) {
				b = true;
			} else if (d >= 1.5 && d < 2) {
				b = true;
			} else if (l >= 1.5 && d < 2) {
				b = true;
			} else {
				b = false;
			}

		} else if (peilvType == 3) {
			if (w >= 2) {
				b = true;
			} else if (d >= 2) {
				b = true;
			} else if (l >= 2) {
				b = true;
			} else {
				b = false;
			}

		} else {
			b = false;
		}
		return b;
	}

	//
	private boolean isRightLeague(SportteryFootballAgainstInfo sportteryFootballAgainstInfo) {
		boolean b = false;
		for (int i = 0; i < leagueNameList.size(); i++) {
			String strItmeLeague = sportteryFootballAgainstInfo.getSimpleLeague().replaceAll("\\s", Config.NULLMARK);
			String strOrderLeague = leagueNameList.get(i).replaceAll("\\s", Config.NULLMARK);
			if (strItmeLeague.equals(strOrderLeague)) {
				b = true;
				break;
			} else {
				b = false;
			}

		}
		return b;
	}
}
